<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

    <div id="app">
      <component v-bind:is="who"></component>
      <button @click="changeComponent">changeComponent</button>
    </div>

    <script>
      var componentA = {
        template: `<div style="color:red;">I'm componentA</div>`,
      };
      var componentB = {
        template: `<div style="color:green;">I'm componentB</div>`,
      };
      var componentC = {
        template: `<div style="color:yellow;">I'm componentC</div>`,
      };

      //   function changeComponent(){

      //   }
      var app = new Vue({
        el: "#app",
        data: { who: componentA },
        components: {
          componentA: componentA,
          componentB: componentB,
          componentC: componentC,
        },
        methods: {
          changeComponent: function () {
            if (this.who == "componentA") {
              this.who = "componentB";
            } else if (this.who == "componentB") {
              this.who = "componentC";
            } else {
              this.who = "componentA";
            }
          },
        },
      });
    </script>
  </body>
</html>
